/**
 * @Author: kesally
 * @Date: 2022-10-08 00:00:00
 * @LastEditTime: 2022-10-08 20:50:00
 * @LastEditors: kesally
 * @Description: 查看群友老婆和老公
 * @FilePath: \Yunzai-Bot\plugins\example\今日群友老婆（改-kesally 加了查群友老公）.js
 * @版权声明
 * @宣传下群不过分吧707499227 作者QQ2770706493
 * @水插件不易，请勿倒卖
 * @原作者717157592 cv了部分代码 再次感谢佬的代码 写的不好请见谅
 **/
import plugin from '../../lib/plugins/plugin.js'
import { segment } from "oicq";
import fetch from 'node-fetch'

let GayCD = {};


export class example extends plugin {
  constructor () {
    super({
      /** 功能名称 */
      name: '今日群友老婆',
      /** 功能描述 */
      dsc: '今日群友老婆',
      /** https://oicqjs.github.io/oicq/#events */
      event: 'message',
      /** 优先级，数字越小等级越高 */
      priority: 4888,
      rule: [
        {
          /** 命令正则匹配 */
          reg: '^今日群友老婆$',
          /** 执行方法 */
          fnc: 'whoismywife'
        },
        {
          /** 命令正则匹配 */
          reg: '^今日群友老公$',
          /** 执行方法 */
          fnc: 'whoismyhusband'
        }
      ]
    })
  }

  async whoismyhusband (e) {
    if(!e.isMaster){
  if(GayCD[e.user_id]){
      e.reply("该命令有2分钟cd");
      return true;
  }
  
  GayCD[e.user_id] = true;
  
  GayCD[e.user_id] = setTimeout(() => {
      if (GayCD[e.user_id]) {
          delete GayCD[e.user_id];
      }
  }, 120000);
    }   
   
   
   
   
   let mmap = await e.group.getMemberMap();
  let arrMember = Array.from(mmap.values());
  let randomhusband = arrMember[Math.round(Math.random() * (arrMember.length-1))];
  let number = Math.ceil(Math.random() * 2);
  
  while(randomhusband.sex != "male"){
      
  randomhusband = arrMember[Math.round(Math.random() * (arrMember.length-1))];
  
  }
  
  if(e.isMaster){
      let msg = [
          segment.at(e.user_id),
          "\n主人好,今天你的群友老公是",
          segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${randomhusband.user_id}`),
          `【${randomhusband.nickname}】 (${randomhusband.user_id}) 哒哒哒！(健康使用不要刷屏！)`
      ]
      
      e.reply(msg);
      
      return true;
  }
  
  
  
   if(number > 1){
  
      let msg = [
          segment.at(e.user_id),
          "\n今天你的群友老公是",
          segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${randomhusband.user_id}`),
          `【${randomhusband.nickname}】 (${randomhusband.user_id}) 哒哒哒！(健康使用不要刷屏！)`
      ]
      
      e.reply(msg);
   }else{
       e.reply(`醒醒,你根本没有老公`)
      }
      return true;
    }
  
  

  //*此处cv了P佬代码 原作者QQ717157592 再次感谢佬*/
  async whoismywife (e) {
      if(!e.isMaster){
  if(GayCD[e.user_id]){
        e.reply("该命令有2分钟cd");
        return true;
    }

    GayCD[e.user_id] = true;

    GayCD[e.user_id] = setTimeout(() => {
        if (GayCD[e.user_id]) {
            delete GayCD[e.user_id];
        }
    }, 120000);
      }   
     
     
     
     
     let mmap = await e.group.getMemberMap();
    let arrMember = Array.from(mmap.values());
    let randomWife = arrMember[Math.round(Math.random() * (arrMember.length-1))];
    let number = Math.ceil(Math.random() * 2);
   
    while(randomWife.sex != "female"){
        
    randomWife = arrMember[Math.round(Math.random() * (arrMember.length-1))];
    
    }
    
    if(e.isMaster){
        let msg = [
            segment.at(e.user_id),
            "\n主人好,今天你的群友老婆是",
            segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${randomWife.user_id}`),
            `【${randomWife.nickname}】 (${randomWife.user_id}) 哒哒哒！(健康使用不要刷屏！)`
        ]
        
        e.reply(msg);
        
        return true;
    }
    
    
     if(number > 1){
   
        let msg = [
            segment.at(e.user_id),
            "\n今天你的群友老婆是",
            segment.image(`https://q1.qlogo.cn/g?b=qq&s=0&nk=${randomWife.user_id}`),
            `【${randomWife.nickname}】 (${randomWife.user_id}) 哒哒哒！(健康使用不要刷屏！)`
        ]
        
        e.reply(msg);
     }else{
         e.reply(`醒醒,你根本没有老婆`)
     }

       
    return true;
  }
}
